# Replication code for Weidmann&Toft
# "Promises and Pitfalls", CMPS 2010
# Nils B. Weidmann, March 2010

library(sp)
library(maptools)

# set your working directory here
setwd("<working directory>")

# Results reported in Section "Null Hypothesis" 
# of the paper (pp. 167ff)
# Experiment 1: Random events of ethnic violence 
# distributed across the entire country (as in original paper)
ex1 <- read.table("experiment1.txt", header=T)
summary(ex1)
quantile(ex1$CORR, probs=c(0.95))

# Experiment 2: Random events placed only 
# in Croatia, Kosovo and Bosnia
ex2 <- read.table("experiment2.txt", header=T)
quantile(ex2$CORR, probs=c(0.99))

# plot distributions (Figure 2)
plot(density(ex1$CORR), xlim=c(-0.4,1), ylim=c(0,12), lwd=2, lty=1, main="Density of correlations")
polygon(c(0.83378, 0.83378, 0.88445, 0.88445), c(13, 0, 0, 13), , border=NA, col="grey")
lines(density(ex2$CORR), lwd=2, lty=2)

# Results reported in Section "Using the 
# LMB Model for Prediction" (pp. 173ff)
# Experiment 3: Restricting observed and 
# simulated events to Bosnia only
ex3 <- read.table("experiment3.txt", header=T)
quantile(ex3$CORR, probs=c(0.05,0.95))
